

*-------------------------------------------------------------------------------
* collect data 
*-------------------------------------------------------------------------------

* isr data
use "data/outputs/ISRpedestrian_beat.dta", clear
collapse (sum) isr_*, by(month)
tempfile isr
save `isr'

* contact card data
use "data/outputs/CC_beat.dta", clear
collapse (sum) pedestrian*, by(month)
renvars pedestrian*, prefix(cc_)
tempfile cc
save `cc'

* traffic stop data
use "data/outputs/TSSS_beat.dta", clear
keep if agencyname == "CHICAGO POLICE"
collapse (sum) count black hispanic citation count_racenonmiss, by(month)
renvars count* black hispanic citation, prefix(itss_)

* merge
merge 1:1 month using `cc'
drop if _m == 2 /* 2009–2011, 2022 */
drop _m
merge 1:1 month using `isr'
drop _m


*-------------------------------------------------------------------------------
* calculate percentages
*-------------------------------------------------------------------------------

* pedestrian series: contact card data pre 2016, ISR data in 2016+
gen pedestrian = cc_pedestrian
replace pedestrian = isr_count_pedestrian if month >= tm(2016m1)
gen pedestrian_black = cc_pedestrian_black
replace pedestrian_black = isr_black_pedestrian if month >= tm(2016m1)

* pedestrian percent black
gen pedestrian_pctblack = pedestrian_black / pedestrian

* traffic percent black
gen tsss_pctblack = itss_black / itss_count

* total fraction black 
gen stops_total = pedestrian + itss_count 
gen black_total = pedestrian_black + itss_black 
gen pctblack_allstops = black_total / stops_total

* shaded region
gen treatment = 1 if month >= tm(2015m8) & month <= tm(2016m1)


*-------------------------------------------------------------------------------
* graph
*-------------------------------------------------------------------------------

#delimit;
twoway (area treatment month if month <= tm(2020m2), 
		lcolor(gs15%100) fcolor(gs15%100))
	(connected pedestrian_pctblack month if month < tm(2020m3), 
		lcolor(gs11%10) mcolor(gs11%50) msize(vsmall))	
	(connected tsss_pctblack month if month < tm(2020m3),
		lcolor(blue%50) mcolor(blue%50) msize(vsmall))
	(connected pctblack_allstops month if month < tm(2020m3), 
		lcolor(red) mcolor(red) msymbol(diamond) msize(small)),
graphregion(fcolor(white) lcolor(white) margin(zero))
plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none))
xsize(7) ysize(5)
title("", 
	  color(black) placement(west) justification(left) size(medlarge)) 
ytitle("Proportion of Stopped People Who Are Black", size(medlarge))
yscale(lcolor(none) )
ylabel(0(.2)1, labsize(large) glcolor(white) angle(horizontal))
xtitle("", size(medsmall)) 
xscale(lcolor(none) range(636 722) )
xlabel(624(12)720, labsize(medlarge) format(%tmCY)) 
legend(order(2 "Pedestrian stops" 4 "All stops" 3 "Traffic stops")
rows(3) pos(4) ring(0) size(medlarge) symxsize(*.5));
graph export "figures/Figure4.pdf", replace;
#delimit cr


* End

